<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<html>
<head>
<title>设备供应商管理</title>
<jsp:include page="../../views/layout/inc.jsp"></jsp:include>

<script type="text/javascript">
	$.canEdit = true;
	$.canDelete = true;
	var dataGrid;
	$(function() {
		dataGrid = $('#dataGrid').datagrid({
			url : '/equipmentProducerController/dataGrid',
			fit : true,
			fitColumns : true,
			border : false,
			pagination : true,
			idField : 'id',
			pageSize : 10,
			pageList : [ 10, 20, 30, 40, 50 ],
			sortName : 'contractTime',
			sortOrder : 'desc',
			checkOnSelect : false,
			selectOnCheck : false,
			nowrap : false,
			frozenColumns : [ [ {
				field : 'name',
				title : '供应商名称',
				width : 100,
				sortable : true
			},{
				field : 'contactPerson',
				title : '联系人名称',
				width : 80,
				sortable : true
			} ] ],
			columns : [ [ {
				field : 'mobile',
				title : '联系人电话',
				width : 80
			}, {
				field : 'address',
				title : '联系人地址',
				width : 110
			}, {
				field : 'proBzCode',
				title : '唯一标识',
				width : 60
			}, {
				field : 'proState',
				title : '状态',
				width : 60,
				formatter:function(val,rec){ 
					if(val == 0) {
						return '';
					}else if(val == 1) {
						return '正常';
					}else if(val == 2) {
						return '冻结';
					}else if(val == 3) {
						return '已删除';
					}
				}
			},{
				field : 'contractTime',
				title : '合作时间',
				width : 110,
				formatter:function(val,rec){
					if(val!='' && val!=null){
						 var unixTimestamp = new Date(val);  
						 return unixTimestamp.format("yyyy-MM-dd hh:mm:ss");
					}
				}
			},{
				field : 'gmtModify',
				title : '更新时间',
				width : 110,
				sortable : true,
				formatter:function(val,rec){
					if(val!='' && val!=null){
						 var unixTimestamp = new Date(val);  
						 return unixTimestamp.format("yyyy-MM-dd hh:mm:ss");
					}
				}
			},{
				field : 'gmtCreate',
				title : '创建时间',
				width : 110,
				sortable : true,
				formatter:function(val,rec){ 
					 var unixTimestamp = new Date(val);  
                     return unixTimestamp.format("yyyy-MM-dd hh:mm:ss");  
				}
				
			},{field:'action',title:'操作',width:100,formatter : function(value, row, index) {
					var str = '';
					if ($.canEdit) {
						str += $.formatString('<img onclick="editDeviceType(\'{0}\');" src="{1}" title="修改"/>', index, '${path}/images/extjs_icons/pencil.png');
					}
					str += '&nbsp;';
					if ($.canDelete) {
						str += $.formatString('<img onclick="delDeviceType(\'{0}\');" src="{1}" title="删除"/>', index, '${path}/images/extjs_icons/cancel.png');
					}
					return str;
				}}
			] ],
			toolbar : '#toolbar',
			onContextMenu : function(e, row) {
				//e.preventDefault();
				$('#menu').menu('show', {
					left : e.pageX,
					top : e.pageY
				});
			},
			onLoadSuccess : function() {
				$('#searchForm').show();
				parent.$.messager.progress('close');
				$(this).datagrid('tooltip');
			}
		});
	});

	function searchFun() {
		dataGrid.datagrid('load', $.serializeObject($('#searchForm')));
	}
	
	function cleanFun() {
		$('#searchForm input').val('');
		dataGrid.datagrid('load', {});
	}
	
	//新增设备供应商
	function addDevSup() {
		parent.$.modalDialog({
			title : '新增供应商',
			width : 500,
			height : 300,
			href : '/equipmentProducerController/addPage',
			buttons : [ {
				text : '确认新增',
				handler : function() {
					parent.$.modalDialog.openner_dataGrid = dataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
					var f = parent.$.modalDialog.handler.find('#form');
					f.submit();
				}
			} ]
		});
	}
	
	//修改
	function editDeviceType(index){
		dataGrid.datagrid("selectRow",index);
		var row = dataGrid.datagrid('getSelected');
		if (row) {
			parent.$.modalDialog({
				title : '修改供应商',
				width : 500,
				height : 300,
				href : '/equipmentProducerController/editPage?id=' + row.id,
				buttons : [ {
					text : '确定修改',
					handler : function() {
						parent.$.modalDialog.openner_dataGrid = dataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
						var f = parent.$.modalDialog.handler.find('#form');
						f.submit();
					}
				} ]
			});
		}
	}
	
	//删除
	function delDeviceType(index){
		dataGrid.datagrid("selectRow",index);
		var row = dataGrid.datagrid('getSelected');
		if (row) {
			if(row.isDel==1){
				parent.$.messager.alert('提示', "该设备类型已删除", 'info');return;
			}
			parent.$.messager.confirm('询问', '您是否要删除该设备类型？', function(b) {
				if (b) {
					parent.$.messager.progress({
						title : '提示',
						text : '数据处理中，请稍后....'
					});
					$.post('/equipmentProducerController/delete', {
						id : row.id
					}, function(result) {
						if (result.success) {
							parent.$.messager.alert('提示', result.msg, 'info');
							dataGrid.datagrid('reload');
						}else{
							parent.$.messager.alert('提示',result.msg,'info');
						}
						parent.$.messager.progress('close');
					}, 'JSON');
				}
			});
		}
	}
	
</script>
</head>
<body>
<div class="easyui-layout" data-options="fit : true,border : false">
		<div data-options="region:'north',title:'查询条件',border:false" style="height: 60px; overflow: hidden;">
			<form id="searchForm">
				<table>
					<tr>
						<th>供应商名称</th>
						<td>
							<input id="name" name="name" placeholder="模糊查询" />
						</td>
					</tr>
				</table>
			</form>
		</div>
		<div data-options="region:'center',border:false">
			<table id="dataGrid"></table>
		</div>
	</div>
	<div id="toolbar" style="display: none;">
		<a onclick="addDevSup();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'">新增</a>
		<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="searchFun();">提交查询</a>
		<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true" onclick="cleanFun();">重置查询</a>
	</div>
		
</body>
</html>